<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">
      <div class="table-page-search-wrapper" v-if="hasPerm('storagePurchase:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="到货入库编码">
                <a-input v-model="queryParam.purchaseStorageCode" allow-clear placeholder="请输入到货入库编码"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="采购订单编码">
                <a-input v-model="queryParam.purchaseOrderCode" allow-clear placeholder="请输入采购订单编码"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :scroll="{x: 1200}"
        :rowKey="(record) => record.id"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="goToViewForm(record)">查看</a>
        </span>
      </s-table>
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import { storagePurchasePage } from '@/api/modular/main/storage/purchase/storagePurchaseManage'
  export default {
    components: {
      STable
    },
    data () {
      return {
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '到货入库编码',
            align: 'center',
            width: 200,
            ellipsis: true,
            dataIndex: 'purchaseStorageCode'
          },
          {
            title: '采购订单编码',
            align: 'center',
            width: 200,
            ellipsis: true,
            dataIndex: 'purchaseOrderCode'
          },
          {
            title: '数量',
            align: 'center',
            width: 100,
            ellipsis: true,
            dataIndex: 'totalQty'
          },
          {
            title: '备注',
            align: 'center',
            ellipsis: true,
            dataIndex: 'remark'
          },
          {
            title: '更新人',
            align: 'center',
            width: 100,
            ellipsis: true,
            dataIndex: 'updateUserName'
          },
          {
            title: '更新时间',
            align: 'center',
            width: 150,
            ellipsis: true,
            dataIndex: 'updateTime'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return storagePurchasePage(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      this.columns.push({
        title: '操作',
        align: 'center',
        width: 100,
        dataIndex: 'action',
        scopedSlots: { customRender: 'action' },
        fixed: 'right'
      })
    },
    activated () {
      this.$refs.table.refresh()
    },
    methods: {
      goToViewForm (record) {
        this.$router.push({
          path: '/storagePurchaseForm/view',
          query: {
            code: record.purchaseStorageCode
          }
        })
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
